package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.SaleList;
import com.atguigu.jxc.entity.SaleListGoods;
import com.atguigu.jxc.service.SaleListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("saleListGoods")
public class SaleListGoodsController {

    @Autowired
    private SaleListGoodsService saleListGoodsService;
    /*
    请求URL：http://localhost:8080/saleListGoods/save?saleNumber=XS1605772263999 （销售单号）
    请求参数：SaleList saleList, String saleListGoodsStr
    请求方式：POST
    返回值类型：JSON
    返回值：ServiceVO
     */
    //销售单保存
    @PostMapping("save")
    public ServiceVO save(SaleList saleList, String saleListGoodsStr, String saleNumber){
        return saleListGoodsService.save(saleList,saleListGoodsStr,saleNumber);
    }

    /*
    请求URL：http://localhost:8080/saleListGoods/list
    请求参数：String saleNumber, Integer customerId, Integer state, String sTime,String eTime
    请求方式：POST
    返回值类型：JSON
    返回值：Map<String,Object>
     */
    //销售单查询（可查询条件：销售单号、客户、付款状态）
    @PostMapping("list")
    public Map<String,Object> list(String saleNumber, Integer customerId, Integer state, String sTime, String eTime){
        List<SaleList> list=saleListGoodsService.list(saleNumber,customerId,state,sTime,eTime);
        Map<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }

    /*
    请求URL：http://localhost:8080/saleListGoods/goodsList
    请求参数：Integer saleListId
    请求方式：POST
    返回值类型：JSON
    返回值：Map<String,Object>
     */
    //销售单商品信息
    @PostMapping("goodsList")
    public Map<String,Object> goodsList(Integer saleListId){
        HashMap<String, Object> map = new HashMap<>();
        List<SaleListGoods> list=saleListGoodsService.goodsList(saleListId);
        map.put("rows",list);
        return map;
    }

    /*
    请求URL：http://localhost:8080/saleListGoods/delete
    请求参数：Integer saleListId
    请求方式：POST
    返回值类型：JSON
    返回值：ServiceVO
     */
    //删除销售单
    @PostMapping("delete")
    public ServiceVO delete(Integer saleListId){
        return saleListGoodsService.delete(saleListId);
    }

    /*
    请求URL：http://localhost:8080/saleListGoods/updateState
    请求参数：Integer saleListId
    请求方式：POST
    返回值类型：JSON
    返回值：ServiceVO
     */
    //支付结算（修改销售单付款状态）
    @PostMapping("updateState")
    public ServiceVO updateState(Integer saleListId){
        return saleListGoodsService.updateState(saleListId);
    }
    /*
    请求URL：http://localhost:8080/saleListGoods/getSaleDataByDay
    请求参数：String sTime, String eTime
    请求方式：POST
    返回值类型：JSON
    返回值：String
     */
    //按日统计接口
    @PostMapping("getSaleDataByDay")
    public List<Map<String,Object>> getSaleDataByDay(String sTime, String eTime){
        List<Map<String,Object>> mapList=saleListGoodsService.getSaleDataByDay(sTime,eTime);
        return mapList;
    }

    /*
    请求URL：http://localhost:8080/saleListGoods/getSaleDataByMonth
    请求参数：String sTime, String eTime
    请求方式：POST
    返回值类型：JSON
    返回值：String
     */
    //按月统计接口
    @PostMapping("getSaleDataByMonth")
    public List<Map<String,Object>> getSaleDataByMonth(String sTime, String eTime){
        return saleListGoodsService.getSaleDataByMonth(sTime,eTime);
    }
}
